package com.bestillet.defaultmultishop;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class OptionDialog extends Dialog {
	private MixActivity context;
	private ListView list;
	
	private Mix mix;
	
	private OnItemClickListener listener = new OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
			mix.setChoice(mix.getOptions().get(position));
			context.updateChoices();
			dismiss();
		}
	};

	public OptionDialog(Context context, Mix mix) {
		super(context);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.dialog_option);
		
		this.context = (MixActivity) context;
		this.mix = mix;
		
		OptionArrayAdapter adapter = new OptionArrayAdapter(context, mix.getOptions());
		list = (ListView) findViewById(android.R.id.list);
		list.setAdapter(adapter);
		list.setOnItemClickListener(listener);
	}
}